package org.jeecg.tool.bean;

import de.schlichtherle.license.*;
import lombok.Data;

import java.io.File;
import java.util.prefs.Preferences;

@Data
public class LicenseVerifierParam {

    private String subject;

    private String storePass;

    private String publicAlias = "publicKey";

    private String licenseRoot;

    private Boolean enabled;

    public LicenseParam toLicenseParam(Class<?> c) {
        Preferences preferences = Preferences.userNodeForPackage(c);
        CipherParam cipherParam = new DefaultCipherParam(getStorePass());
        KeyStoreParam publicStoreParam = new MyKeyStoreParam(c, getPubKeyPath(),
                getPublicAlias(), getStorePass(), null);
        return new DefaultLicenseParam(getSubject(), preferences, publicStoreParam, cipherParam);
    }

    private String getPubKeyPath() {
       return licenseRoot + File.separator + "public.key";
    }

    public String getLicPath() {
        return licenseRoot + File.separator + "license.lic";
    }
}
